<?php
/** .-------------------------------------------------------------------
* |  Software: [HDCMS framework]
* |      Site: www.hdcms.com
* |-------------------------------------------------------------------
* |    Author: 向军 <2300071698@qq.com>
* |    WeChat: aihoudun
* | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
* '-------------------------------------------------------------------*/

namespace app\home\controller;


class Order extends Common{

    private $db;
    public function __construct() {
       $this->db= new  \system\model\Address();
    }

    //动作
    public function index(){
    //此处书写代码...
//        p($_SESSION);die;
        if(!isset($_SESSION['cart']['total'])){
            message('没有商品，请购物',u('entry.index'),'success');
        }
        $uid=$_SESSION['home']['uid'];
        if(!$uid){
            go('home.logoin.logo');
        }
        if(IS_POST){
//            p($_POST);die;
            if($this->db->address()){
                message('地址添加成功','','success');
            }
            message($this->db->getError(),'','error');
        }

        $Address=Db::table('address')->get();
//        p($Address);
        View::with('Address',$Address);

        return view();
    }

    public function del(){
        $adid=Q('get.adid');
        $this->db->where('adid',$adid)->delete();
        message('删除成功','','success');
    }

    public function order(){
        //获取地址id
        $adid=Q('post.adid');
        if(!isset($adid)){
            message('请选择地址！！',u('order.index'),'success');
        }
        if(IS_POST){

            $data=new \system\model\Order();
            $oid=$data->order();
            if($oid){
                message('提交成功',u('payMent.index',['oid'=>$oid]),'success');
            }
                message($this->db->getError(),'','error');
        }
    }


}
